<?php
	require_once PATH_OBJECT.'dataObject.php';
	
class dataObject_habilitation extends dataObject
{
 	/**
 	 * @desc    Identifiant de l'habilitation
     * @var     int
     */
    public $_IDENTIFIANT_HABILITATION = 0;
    
    /**
     * @desc    code de l'evenement sur lequel on a l'habilitation
     * @var     char
     */
    public $_CODE_EVENEMENT = '';

    /**
     * @desc   Libelle de l'evenement sur lequel on a l'habilitation
     * @var     varchar
     */
    public $_LIBELLE_EVENEMENT = '';
    
    /**
     * @desc    Identifiant du menu parent directement rattaché s'il existe.
     * @var     int
     */
    public $_IDENTIFIANT_PROFIL = 0;
    
	public function __construct( $iId=0 )
    {
       parent::__construct();

       if ( $iId != 0 )
       {
            $sQuery = "SELECT   *   /*+ dataObject_habilitation::__construct */  
                       FROM habilitation 
            		   WHERE Identifiant_habilitation = ".$iId;
            
            $aRows =  self::$_oConnexion->query($sQuery);
			$aRow = $aRows[0];
        
            $this->_IDENTIFIANT_HABILITATION      	= $iId;
            $this->_CODE_EVENEMENT           		= $aRow["Code_evenement"];
            $this->_LIBELLE_EVENEMENT     			= $aRow["Libelle_evenement"];
            $this->_IDENTIFIANT_PROFIL        		= $aRow["Identifiant_profil"];
          
       }
    }

	public function habilitation_hasDroit($sCodeDroit, $idGroupe=0)
	{
		if($idGroupe==0)
		{
			if (isset($_SESSION['MM_UserGroup']) && $_SESSION['MM_UserGroup']!=NULL)
				$idGroupe = intval($_SESSION['MM_UserGroup']);
		}
		$sCodeDroit = strtoupper(substr($sCodeDroit, 0,5)); 
		$sQuery = "SELECT * FROM habilitation 
				WHERE Identifiant_profil = ".$idGroupe
				." and Code_evenement = '".$sCodeDroit."'";
		$aRow =  self::$_oConnexion->query($sQuery);
		/* FS 22/10/2010 boucle foreach inutile
		$sCodEven = "";
		$n = 0;
		foreach($aRow as $iKey => $sRow)
		{
			$sCodEven = strtoupper($sRow['Code_evenement']);
			echo "<br>".$sCodEven." et ".$sCodeDroit;
			if($sCodEven == $sCodeDroit)
			{ 
				$n += 1; 
				$_SESSION["$sCodeDroit"] = $sCodeDroit; 
			}
			
		}
		if($n==0) return 'none' ; */
		
		if(empty($aRow)) return 'none' ;
	}
}
?>